package Controller;


import Model.SignRecord;
import Service.SignRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import utils.pages.Page;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/SignRecord")
public class SignRecordController {

    private static final Logger logger = LoggerFactory.getLogger(SignRecordController.class);

    @Autowired
    private SignRecordService signRecordService;

    /**
     * pc查询所有管理签到/签退记录
     * @return
     */
    @RequestMapping(value = "/getSignRecord", method = RequestMethod.GET)
    @ResponseBody
    public List<SignRecord> getSignRecord(){
        List<SignRecord> signList = signRecordService.findSignRecord();
        return signList;
    }

    /**
     * 条件查询签到/签退记录
     * @param page
     * @param vId
     * @param vHG
     * @return
     */
    @RequestMapping("/getSignRecordbyName")
    public String getSignRecordbyName(@RequestParam(defaultValue = "1") Integer page, Model model,
                                            Integer vId, Integer vHG, Integer vLR,HttpSession session){
        System.out.println("表现层：条件查询课程信息");
        Integer pageNum = 10; //默认每页显示10条记录
        Page<SignRecord> list = signRecordService.getSignRecordbyName(vId,vHG,vLR,page,pageNum);
        //System.out.println("查询结果："+list.getRows());
        model.addAttribute("page",list);
        return "/SmartCheck/SignInfo/SignRecord";
    }

    /**
     * 条件查询异常预警
     * @param page
     * @param vId
     * @param vHG
     * @return
     */
    @RequestMapping("/getAbnormalbyName")
    public String getAbnormalbyName(@RequestParam(defaultValue = "1") Integer page, Model model,
                                      Integer vId, Integer vHG, Integer vLR,HttpSession session){
        System.out.println("表现层：条件查询课程信息");
        Integer pageNum = 10; //默认每页显示10条记录
        Page<SignRecord> list = signRecordService.getAbnormalbyName(vId,vHG,vLR,page,pageNum);
        //System.out.println("查询结果："+list.getRows());
        model.addAttribute("page",list);
        return "/SmartCheck/SignInfo/AlarmRecord";
    }

    /**
     * pc删除管理签到/签退记录
     * @return
     */
    @RequestMapping(value = "/delSignRecord")
    @ResponseBody
    public String delSignRecord(@RequestParam("id") int id){
        int rows = signRecordService.delSignRecord(id);
        try {
            if (rows > 0) {
                return "OK";
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("删除记录异常！", e);
        }
        return "FAIL";
    }

}
